package com.example.Utils;

import com.example.Entity.Vo.APIResult;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import javax.annotation.Resource;

@Component
public class SendEmailTemplatesUtils {
    @Resource
    TemplateEngine templateEngine;
    @Resource
    SendEmailUtils sendEmailUtils;
    public APIResult SendTemplateEmail(String template, String from, String to, Context ctx, String suject){
        try {
            String mail = templateEngine.process(template,ctx);
            sendEmailUtils.SendEmailTemplate(from,to, suject,mail);
            return APIResultUtils.success("发送成功");
        }
        catch (Exception e){
            return APIResultUtils.error("邮件发送失败",e.getMessage());
        }
    }
}
